package com.example.toutiao.ui.main.act


import androidx.recyclerview.widget.LinearLayoutManager
import com.example.toutiao.R
import com.example.toutiao.base.BaseActivity
import com.example.toutiao.ui.main.adpater.CityAdapter
import com.example.toutiao.ui.main.model.AddressModel
import com.example.toutiao.ui.main.presenter.AddressPresenter
import com.example.toutiao.ui.main.view.AddressView
import com.example.toutiao.ui.user.EvtMsgModel
import kotlinx.android.synthetic.main.activity_city.*

class CityActivity : BaseActivity<AddressView, AddressPresenter>(), AddressView {
    private var province:String?=null
    override fun getLayoutId(): Int = R.layout.activity_city

    override fun initView() {
        if(intent!=null){
            province=intent.getStringExtra("province")
            tv_nav_title.text=province
        }
        icon_back.setOnClickListener { finish() }
    }

    override fun initData() {
        getPresenter()!!.getCity(1001)

    }

    override fun createPresenter(): AddressPresenter = AddressPresenter()

    override fun isRegister(): Boolean =true

    override fun <T> setData(data: T) {
        val mList = data as MutableList<AddressModel>
        rv_address_list.layoutManager = LinearLayoutManager(this)
        val adapter = CityAdapter(mList)
        rv_address_list.adapter = adapter
        adapter.setOnClickListener(object: CityAdapter.OnClickListener{
            override fun OnClick(title: String) {
                postMsg(EvtMsgModel(301,"$province $title"))
                finish()
            }
        })
    }

    override fun setError(err: String) {

    }

}